
class Student(object):
    def __init__(self,name,gender):
        self.__name=name
        self.__gender=gender
    def set_gender(self,gender):
        if gender in ['male', 'female']:
            self.__gender=gender
        else:
            raise ValueError('bad gender')
    def get_gender(self):
        return self.__gender
# 测试:
bart = Student('Bart', 'male')
if bart.get_gender() != 'male':
    print('测试失败!')
else:
    bart.set_gender('female')
    if bart.get_gender() != 'female':
        print('测试失败!')
    else:
        print('测试成功!')

class Animal(object):
    def run(self):
        print('Animal is runing...')
class Dog(Animal):
    def run(self):
        print('Dog is running...')
class Cat(Animal):
    def run(self):
        print('cat is running...')
dog=Dog()
dog.run()
cat=Cat()
cat.run()

class Student(object):
    count=0
    def __init__(self,name):
        self.name=name
        Student.count=Student.count+1

# 测试:
if Student.count != 0:
    print('测试失败!')
else:
    bart = Student('Bart')
    if Student.count != 1:
        print('测试失败!')
    else:
        lisa = Student('Bart')
        if Student.count != 2:
            print('测试失败!')
        else:
            print('Students:', Student.count)
            print('测试通过!')
class Student(object):
    def get_score(self):
        return self._score
    def set_score(self,value):
        if not isinstance(value,int):
            raise ValueError('score must be an integer!')
        if value<0 or value>100:
            raise ValueError('score must between 0-100!')
        self._score=value
        

class Student(object):
    @property
    def score(self):
        return self._score
    @score.setter
    def score(self,value):
        if not isinstance(value,int):
            raise ValueError('score must be ancinteger!')
        if value<0 or value>100:
            raise ValueError('score must between 0-100!')
        self._score=value

class Student(object):
    @property
    def birth(self):
        return sself._birth
    @birth.setter
    def birth(self,value):
        self._birth=value
    @property
    def age(self):
        return 2024-self._birth
    

class Screen(object):
    @property
    def width(self):
        return self._width
    @width.setter
    def width(self,width):
        self._width=width
    @property
    def height(self):
        return self._height
    @height.setter
    def height(self,height):
        self._height=height
    @property
    def resolution(self):
        return self._width*self._height
# 测试:
s = Screen()
s.width = 1024
s.height = 768
print('resolution =', s.resolution)
if s.resolution == 786432:
    print('测试通过!')
else:
    print('测试失败!')
